home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / appl / napsaterm / national.c < prev    next >
C/C++ Source or Header  |  1994-05-14  |  4KB  |  168 lines

  1. /* $Id: national.c,v 3.1 1994/01/07 22:51:34 ppessi Exp $
  2.  * 
  3.  * national.c --- handle national fonts and keyboard layouts
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * Copyright (c) 1993 Pekka Pessi
  8.  *
  9.  * Created      : Mon Mar 29 06:32:31 1993 ppessi
  10.  * Last modified: Wed Jan  5 07:51:36 1994 ppessi
  11.  *
  12.  */
  13.  
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <ctype.h>
  17.  
  18. #include "nifty.h"
  19. #include "napsaprefs.h"
  20. #include "amiga.h"
  21. #include "wimp.h"
  22.  
  23. #define MAX_NATIONS 31
  24.  
  25. struct nation {
  26.   const char *n_kmapname;    /* name of the kmap resource */
  27.   void *n_kmap;            /* pointer to the kmap resource */
  28.   const char *n_patches;    /* mapping between Latin1 and national code */
  29. };
  30.  
  31. unsigned char national_show[CHARSETSIZE];
  32. unsigned char national_send[CHARSETSIZE];
  33.  
  34. /*
  35.  * Note that US* has synonymes
  36.  */
  37. char nation_names[] =
  38.   "US ASCII" NUL "Danish" NUL "Finnish" NUL "French" NUL
  39.   "German" NUL "Norwegian" NUL "Swedish" NUL "UK ASCII" NUL;
  40.  
  41. static struct nation nations[MAX_NATIONS] = 
  42.   /* US-ASCII */
  43.   { "usa1", NULL, NULL },
  44.   /* Danish */
  45.   { "dk", NULL, 
  46.       /* Danish I [Æ]Å\Ø{æ}å|ø */  
  47.       "[\306]\305\\\330{\346}\345|\370" }, 
  48.   /* Finnish */
  49.   { "s", NULL, 
  50.       /* [Ä]Å\Ö{ä}å|ö */  
  51.       "[\304]\305\\\326{\344}\345|\366" }, 
  52.   /* French */
  53.   { "f", NULL, 
  54.       /* @à[°\ç]§{é|ù}è~¨ */  
  55.       "@\340[\227\\\337]\305{\351|\371}\350~\250" }, 
  56.   /* German */
  57.   { "d", NULL,
  58.       /* @§[Ä]Ü\Ö{ä}ü|ö~ß */
  59.       "@\247[\304]\334\\\326{\344}\374|\366~\337" },
  60.   /* Norwegian */
  61.   { "n", NULL, 
  62.       /* $¤@É[Æ]Å\Ø^Ü`é{æ}å|ø~ü */
  63.       "$\244@\311[\306]\305\\\330^\334`\351{\346}\345|\370~\374" },
  64.   /* Swedish */
  65.   { "s", NULL, 
  66.       /* $¤@É[Ä]Å\Ö^Ü`é{ä}å|ö~ü */
  67.       "$\244@\311[\304]\305\\\326^\334`\351{\344}\345|\366~\374" },
  68.   /* UK */
  69.   { "gb", NULL,
  70.       /* british #£*/ 
  71.       "#\243" },
  72. }; /* ASCII */
  73.  
  74. static struct nation *used_nation = NULL;
  75. static short used_nation_number;
  76. static short no_nation = 7;
  77.  
  78. static unsigned char kmap_template[] =
  79. "\000\001\002\003\004\005\006\007"
  80. "\010\011\012\013\014\015\016\017"
  81. "\020\021\022\023\024\025\026\027"
  82. "\030\031\032\033\034\035\036\037"
  83. " !c#$Y|#@ca\"--r-o+23'uP.,1o\"   ?"
  84. "AAAAAAACEEEEIIIIDNOOOOO*OUUUUYTs"
  85. "aaaaaaaceeeeiiiidnooooo/ouuuuyty";
  86.  
  87. /*
  88.  * initialize current mapping
  89.  */
  90. void setnation(unsigned int n)
  91. {
  92.   int i;
  93.   const unsigned char *patch;
  94.  
  95.   if (n >= no_nation)
  96.     return;
  97.  
  98.   if (used_nation == nations + n)
  99.     return;
  100.  
  101.   used_nation = nations + n;
  102.   used_nation_number = n;
  103.  
  104.   for (i = 0; i < CHARSETSIZE; i++) {
  105.     national_send[i] = national_show[i] = i;
  106.   }
  107.  
  108.   /* Set the keymap */
  109.   used_nation->n_kmap = 
  110.     setmap(used_nation->n_kmapname, used_nation->n_kmap);
  111.  
  112.   /* patch send & receive tables */
  113.   memcpy(national_send + 128, kmap_template, 128);
  114.   for (patch = used_nation->n_patches; patch && *patch; patch += 2) {
  115.     national_send[patch[1]] = patch[0];
  116.     national_show[patch[0]] = patch[1];
  117.   }
  118. }
  119.  
  120. /*
  121.  * Parse keymap resource
  122.  */
  123. int parsekeymap(char *s, void * dummy)
  124. {
  125.   char *mapname = PathPart(s);
  126.  
  127.   /* Are we only given the mapname? */ 
  128.   if (mapname == s) {
  129.     np.keymap = s;
  130.     return 1;
  131.   } else if (*mapname == '/') {
  132.     int i;
  133.     const char *t = nation_names;
  134.  
  135.     *mapname++ = '\0';    /* NUL terminate the map name */
  136.  
  137.     if (!Stricmp("ASCII", s)) {
  138.       nations[0].n_kmapname = mapname;
  139.       return 1;
  140.     }
  141.  
  142.     for (i = 0; *t; i++) {
  143.       if (!Strnicmp(t, s, 2)) {
  144.     /* Found nation */
  145.     nations[i].n_kmapname = mapname;
  146.     return 1;
  147.       }
  148.       while (*t++)
  149.     ;
  150.     }
  151.     /* Illegal nation, don't set keymap */
  152.     perrorparse("Illegal nation %s", s);
  153.   }
  154.   free(s);
  155.   return 0;
  156. }
  157.  
  158.  
  159. void initnations(void)
  160. {
  161.   setnation(np.nation);
  162. }
  163.  
  164. void deinitnations(void)
  165. {
  166. }
  167.